<template>
    <div class="flex_row_center">
        <!-- 循环显示每个数字 -->
        <span v-for="(item, index) in nums" :key="index" class="number_item flex_column">
            <div class="flex_column scroll_content" :style="{ transform: `translateY(-${px2vw(Number(item) * 26, 1920, 100)})` }">
                <!-- 循环显示0-9 -->
                <i v-for="(n, i) in 10" :key="i" class="scroll_item flex_column flex_center">{{ n - 1 }}</i>
            </div>
        </span>
    </div>
</template>

<script setup lang="ts">
import { computed, onMounted, ref, watch } from "vue";
import { px2vw } from "../../utils/string.util";
interface Props {
    num: number | string;
    maxLength?: number;
    color?: string;
}

// 定义组件属性并设置默认值
const props = withDefaults(defineProps<Props>(), {
    maxLength: 0,
    num: 0,
    color: "#ACCEE0",
});

// 计算文本颜色
const textColor = computed(() => {
    return props.color;
});

// 计算显示的数字
const nums = computed(() => {
    let tNum = props.num;
    if (typeof props.num === "number") {
        tNum = props.num.toString();
    }
    if (props.maxLength && String(tNum).length < props.maxLength) {
        return String(tNum).padStart(props.maxLength);
    }
    return tNum;
});

const top = ref("0px");

onMounted(() => {
    // 组件挂载时的逻辑
});
</script>

<style scoped>
.number_item {
    width: 26px;
    height: 24px;
    margin-right: 8px;
    overflow: hidden;
    background: #0b294f;

    text-align: center;
    line-height: 24px;
}

.scroll_item {
    width: 26px;
    height: 26px;
    line-height: 26px;
    color: v-bind(textColor); /* 绑定文本颜色 */
    font-weight: bold;
    font-size: 20px;
}

.scroll_content {
    transition: all 0.5s ease-out;
    transform: translateY(v-bind(top)); /* 绑定滚动位置 */
}
</style>
